from WSThread import WSThread
import queue, requests, re, time, sys

class DnsFindersGoogleThread(WSThread):
	def __init__(self, result, job, counter):
		super().__init__(job, result)
		self.counter = counter
	
	def run(self):
		linkRe = re.compile(r"<cite>(\S*)</cite>")
		
		while self.running:
			try:
				domain = self.job.get_nowait()
				i = 0
				while True:
					content = requests.get("https://www.google.ru/search?q=site:" + domain + "&start=" + str(i)).text;
					sys.stdout.flush()
					i += 10
					self.counter.up()
					
					founds = linkRe.findall(content)
					if len(founds):
						for found in founds:
							found = found[0:found.find("/")]
							self.result.put(found)
					if len(founds) != 10:
						break
			except queue.Empty:
				self.running = False
		
		